﻿using System;
using Autofac;
using ReactiveGraph.Core;
using ReactiveGraph.Core.Configuration.Containers;

namespace ReactiveGraph.Tests.Containers
{
    public class AutofacTestContainer : IReactiveNodeContainer
    {
        private readonly IContainer _container;
        private readonly ContainerBuilder _builder;

        public AutofacTestContainer()
        {
            _builder = new ContainerBuilder();
            _builder.RegisterModule<AutofacCoreModule>();
            _container = _builder.Build();
        }

        public T GetNode<T>() where T : class, IReactiveNode
        {
            return _container.Resolve<T>();
        }

        public T GetNode<T>(string name) where T : class, IReactiveNode
        {
            var func = _container.Resolve<Func<string,Type, IReactiveNode>>();
            return  (T) func(name, typeof(T));
        }
    }
}
